#include <iostream>
using namespace std;

class Parent
{
public:
 	char *s;
	Parent()
	{
		s="pppp";
	}
	void print()
	{
		cout<<"Parent : "<<s<<endl;
	}
};

class Child : public Parent
{
public:
     Child()
     {
     	s="cccccc";
     }
	 virtual void print()
	{
		cout<<"Child : "<<s<<endl;
	}
};

void howToPrint(Parent* p)//定义的指针对象指向父类
{
	p->print();
}

int main()
{

	Child child;
	Parent p;
	Parent* pp = &child;
	Parent& rp = child;

	child.print();//指向子类print

	//通过指针
	pp->print();//指向子类print
	//通过引用
	rp.print();//指向子类print

	howToPrint(&child);//指向子类print
    howToPrint(&p);//指向父类
	howToPrint(pp);//指向子类print
	howToPrint(&rp);//指向子类print

	return 0;
}